import Vue from 'vue'
import Vuex from 'vuex'

//引入封装好的模块
import menu from './modules/menu/index.js'
import role from './modules/role/index.js'
import user from './modules/control/index'
import cate from './modules/cate/index'
import specs from './modules/specs/index'
import spgl from './modules/spgl/index'
import member from './modules/member/index'
import banner from './modules/banner/index'
import seck from './modules/seck/index'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // userInfo: sessionStorage.setItem ('userinfo') ?  : null,
    userInfo: sessionStorage.getItem("userinfo")
    ? JSON.parse(sessionStorage.getItem("userinfo"))
    : null,
  },
  getters: {
    getUser(state){
      return state.userInfo
    }
  },
  mutations: {

    REQ_USERINFO(state,payload){
      if(payload){
        state.userInfo=payload;
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem('userinfo')
        state.userInfo = null
      }
      
    }
  },
  actions: {
    changeUserInfo({commit},payload){
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    
    cate,
    specs,
    spgl,
    // 会员
    member,
    banner,
    seck

   

  }
})
